#pragma once
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glad/glad.h>

class Camera {
public:
    glm::quat rotation;
    glm::mat4 lookAt;
    glm::vec3 up = glm::vec3(0, 1, 0);
    glm::vec3 right = glm::vec3(1, 0, 0);
    glm::vec3 front = glm::vec3(0, 0, -1);
    glm::vec3 position = glm::vec3(0, 0, 0);
public:
    void SetPosition(const glm::vec3& position) {
        this->position = position;
        Update();
        std::cout << this->up.x << " " << this->up.y << " " << this->up.z << std::endl;
    }
private:
    /*void Update() {
        // 计算正交基
        const auto to = glm::normalize(target - position);
        this->right = glm::cross(to,  glm::vec3(0, 1, 0));
        this->up = glm::cross(to, this->right);
        // 构建LookAt矩阵
        lookAt[0] = glm::vec4(right.x, right.y, right.z, 0);
        lookAt[1] = glm::vec4(up.x, up.y, up.z, 0);
        lookAt[2] = glm::vec4(to.x, to.y, to.z, 0);
        lookAt[3] = glm::vec4(0, 0, 0, 1);

        glm::mat4 p;
        p[0] = glm::vec4(1, 0,0, -position.x);
        p[1] = glm::vec4(0, 1,0, -position.y);
        p[2] = glm::vec4(0, 0, 1, -position.z);
        p[3] = glm::vec4(0, 0, 0, 1);

        lookAt = p * lookAt;
    }*/

    void Update() {
        front = glm::normalize((position + glm::vec3(0, 0, -1)) - position);
        this->right = glm::cross(front,  glm::vec3(0, 1, 0));
        this->up = glm::cross(this->right, front);

        lookAt = glm::lookAt(position, position + front, up);
    }
};
